package com.project.hf.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;


@Component
public class ReadConfig {

    //获取application.properties的属性

    private static String Mysql_JDBC_DRIVER;

    private static String Mysql_DB_URL;

    private static String Mysql_USER;
    private static String Mysql_PASS;
    private static String Oracle_JDBC_DRIVER;

    private static String Oracle_DB_URL;

    private static String Oracle_USER;
    private static String Oracle_PASS;

    @Autowired
    private ReadConfig(@Value("${db.mysql.JDBC_DRIVER}") String Mysql_JDBC_DRIVER,
                       @Value("${db.mysql.DB_URL}") String Mysql_DB_URL,
                       @Value("${db.mysql.USER}") String Mysql_USER,
                       @Value("${db.mysql.PASS}") String Mysql_PASS,
                       @Value("${db.oracle.JDBC_DRIVER}") String Oracle_JDBC_DRIVER,
                       @Value("${db.oracle.DB_URL}") String Oracle_DB_URL,
                       @Value("${db.oracle.USER}") String Oracle_USER,
                       @Value("${db.oracle.PASS}") String Oracle_PASS) {
        this.Mysql_JDBC_DRIVER = Mysql_JDBC_DRIVER;
        this.Mysql_DB_URL = Mysql_DB_URL;
        this.Mysql_USER = Mysql_USER;
        this.Mysql_PASS = Mysql_PASS;
        this.Oracle_JDBC_DRIVER = Oracle_JDBC_DRIVER;
        this.Oracle_DB_URL = Oracle_DB_URL;
        this.Oracle_USER = Oracle_USER;
        this.Oracle_PASS = Oracle_PASS;
    }


    private static ReadConfig instance = new ReadConfig(Mysql_JDBC_DRIVER, Mysql_DB_URL, Mysql_USER, Mysql_PASS,
                                                        Oracle_JDBC_DRIVER,Oracle_DB_URL,Oracle_USER,Oracle_PASS);

    public static ReadConfig getConfigUtil() {
        return instance;
    }

    public Map<String, String> getDBConfig() {
        Map<String, String> map = new HashMap<String, String>();
        map.put("Mysql_JDBC_DRIVER", Mysql_JDBC_DRIVER);
        map.put("Mysql_DB_URL", Mysql_DB_URL);
        map.put("Mysql_USER", Mysql_USER);
        map.put("Mysql_PASS", Mysql_PASS);
        map.put("Oracle_JDBC_DRIVER", Oracle_JDBC_DRIVER);
        map.put("Oracle_DB_URL", Oracle_DB_URL);
        map.put("Oracle_USER", Oracle_USER);
        map.put("Oracle_PASS", Oracle_PASS);
        return map;
    }
    //getter & setter
}
